//
//  MainFirst_Magazine_TBV_HeadCell_WX.m
//  ZITHER
//
//  Created by weixin on 2018/10/18.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "MainFirst_Magazine_TBV_HeadCell_WX.h"
#import "Ugc_HomePage_VC_V3.h"

@implementation MainFirst_Magazine_TBV_HeadCell_WX

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = [UIColor whiteColor];
    // Initialization code
    [self setUI];
    [self setMasonry];
}


-(void)setModel:(HomePageDetailModelData *)model{

    _model = model;
    NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,model.userPgc.coverImg];
    self.cover.contentMode = 0;
    [self.cover sd_setImageWithURL:[NSURL URLWithString:str] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        NSLog(@"");
        CGFloat imageH = 1;
        CGFloat imageW = 1;
        if (image.size.width>imageW) {
            imageW = image.size.width;
        }
        if (image.size.height>imageH) {
            imageH = image.size.height;
        }
        [self.cover mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(0);
            make.height.mas_equalTo(kScreenW/imageW*imageH);
        }];
    }];


  //NaviHeight
    
    
    
    self.title.text = model.userPgc.pgcTitle;
    [self.userPic sd_setImage:model.userPgc.avatar];
    self.userName.text = model.userPgc.nickName;
    self.time.text =[ model.userPgc.releaseTime convertCurrentTime];;
    self.readNum.text = model.userPgc.cheatingCount;
}

-(void)setUI{
    
    [self addSubview:self.cover];
    [self addSubview:self.title];
    [self addSubview:self.userPic];
    [self addSubview:self.userName];
    [self addSubview:self.time];
    [self addSubview:self.readNum];
}

-(void)setMasonry{
    
    [self.cover mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self).offset(0);
        make.height.mas_equalTo(kScreenW/375.0*413);
    }];
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cover.mas_bottom).offset(12);
        make.left.equalTo(self).offset(14);
        make.right.equalTo(self).offset(-14);
    }];

    [self.userPic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.title.mas_bottom).offset(20);
        make.left.equalTo(self).offset(14);
        make.height.width.mas_equalTo(30);
        /** -40 */
        make.bottom.equalTo(self).offset(-15);
    }];

    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.userPic.mas_centerY).offset(-10);
        make.left.equalTo(self.userPic.mas_right).offset(12);
    }];

    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.userPic.mas_centerY).offset(10);
        make.left.equalTo(self.userPic.mas_right).offset(12);
    }];
    
    BaseView *view = [[BaseView alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    view.backgroundColor = [UIColor colorWithHex:@"dedede"];
    [self addSubview:view];
    
    BaseImageV *viewImage =[[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 0, 1) contentMode:2];
    viewImage.image = [UIImage imageNamed:@"pgc_浏览量"];
    [self addSubview:viewImage];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.time.mas_centerY).offset(0);
        make.left.equalTo(self.time.mas_right).offset(8);
        make.height.mas_equalTo(10);
        make.width.mas_equalTo(1);
    }];
    
    [viewImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.time.mas_centerY).offset(0);
        make.left.equalTo(view.mas_right).offset(10);
    }];
    
    [self.readNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.time.mas_centerY).offset(0);
        make.left.equalTo(viewImage.mas_right).offset(10);
    }];
    
}

-(BaseImageV *)cover{
    if (!_cover) {
        _cover = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 1, 1) contentMode:2];
    }
    return _cover;
}

-(BaseLab *)title{
    if (!_title) {
        _title = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 1, 1) text:@"大标题大标题" font:38 textColor:nil isBold:YES numberOfLines:2];
        _title.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:26];

    }
    return _title;
}

-(BaseImageV *)userPic{
    if (!_userPic) {
        _userPic = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 1, 1) contentMode:2];
        [_userPic setCornerRadiusWithRadius:15 isMasks:YES];
        @weakify(self);
        /** 添加点击事件 */
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            @strongify(self);
            Ugc_HomePage_VC_V3 *vc = [[Ugc_HomePage_VC_V3 alloc]init];
            vc.userName = self.model.userPgc.nickName;
            vc.userId = self.model.userPgc.userId;
            vc.userAvatar =  self.model.userPgc.avatar;
            [self.getNav pushViewController:vc animated:YES];
        }];
        _userPic.userInteractionEnabled = YES;
        [_userPic addGestureRecognizer:tap];
    }
    return _userPic;
}


-(BaseLab *)userName{
    if (!_userName) {
        _userName = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 1, 1) text:@"用户姓名" font:14 textColor:[UIColor colorWithHex:@"333333"] isBold:NO numberOfLines:1];
        _readNum.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:13];

    }
    return _userName;
}


-(BaseLab *)time{
    if (!_time) {
        _time = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 1, 1) text:@"刚刚" font:14 textColor:[UIColor colorWithHex:@"999999"] isBold:NO numberOfLines:1];
        _time.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];

    }
    return _time;
}


-(BaseLab *)readNum{
    if (!_readNum) {
        _readNum = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 1, 1) text:@"刚刚" font:14 textColor:[UIColor colorWithHex:@"999999"] isBold:NO numberOfLines:1];
        _readNum.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];

    }
    return _readNum;
}


@end
